/**
 * 
 */
package club325.webchat.database.hibernate.implement;

import java.util.List;

import org.hibernate.Query;

import club325.webchat.database.hibernate.dao.HibernateUtil;
import club325.webchat.database.hibernate.dao.IPPreventDAO;
import club325.webchat.database.hibernate.domain.IPPrevent;

/**
 * @author Sider
 *
 */
public class IPPreventImplement implements IPPreventDAO
{

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.IPPreventDAO#saveIPPrevent(java.lang.String)
	 */
	public void saveIPPrevent(IPPrevent IP)
	{
		HibernateUtil.add(IP);
	}

	/* (non-Javadoc)
	 * @see club325.webchat.database.hibernate.dao.IPPreventDAO#removeIPPrevent(java.lang.String)
	 */
	public void removeIPPrevent(IPPrevent IP)
	{
		HibernateUtil.delete(IP);
	}

	public IPPrevent getIPPreventbyIP(String IP)
	{
		String HQL = "FROM IPPrevent as ipprv WHERE ipprv.IP = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0, IP);
		return (IPPrevent) q.uniqueResult();
	}

	public List<IPPrevent> getAllPrevent()
	{
		String HQL = "FROM IPPrevent as ipprv";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		return q.list();
	}
}